<%@ page language="java" pageEncoding="utf-8"%>
<%@ page import="wpmp.security.client.utils.UserUtils"%>
<%@ include file="/commons/taglibs.jsp"%>
<html>
<head>
<title>新增/更新用户</title>
<%@ include file="/commons/meta.jsp" %>
<%@ include file="/commons/header.jsp" %>
<%@ include file="/extjs/jsps/importExt.jsp" %>
<%@ include file="/extjs/jsps/importEasyExt.jsp" %>
<script language="javascript" type="text/javascript">
var saveCounter=0;

function closeCurrentWindow() {
	var winId='${winId}';
	var closeWin=Ext.WindowMgr.get(winId);
	if(closeWin==null){
		closeWin=parent.Ext.WindowMgr.get(winId);
	}
	if(closeWin==null){
		window.returnValue=(saveCounter>0);
		window.close();
	}else{
		closeWin.returnValue=(saveCounter>0);
		closeWin.close();
	}
}

var formPanel = new Ext.form.FormPanel({
	bodyStyle: 'padding:8 8 8 8;',
	border: false,
	layout: 'form',
	frame: false,
	autoWidth: true,
	autoScroll: true,
	labelAlign: 'right',
	labelWidth: 65,
	items: [{
		border: false,
		layout: 'column',
		items: [{
			// 第1列
			columnWidth : .33,
			border: false,
			layout: 'form',
			defaults: {
				anchor: '100%',
				msgTarget: 'qtip',
				validateOnBlur: false
			},
			items: [{
				name: 'id',
				xtype: 'hidden'
			},{
				allowBlank : false,
				fieldLabel: '登录名',
				xtype: 'textfield',
				name: 'loginName',
				maxLength: 32
			},{  
				name: 'orgId',  
				xtype: 'hidden' 
			},{
				allowBlank: false,
				fieldLabel: '组织/单位',
				name: 'orgName',
				xtype: 'trigger',
				editable: false,
				triggerClass: 'x-form-date-trigger',
				onTriggerClick: function(eventObject) {
					var orgName=this;
					var url="${ctx}/org!select.action?winId=winSelectOrg&U="+(new Date().getTime());
					windowOpen(url,'winSelectOrg','选择组织/单位',225,320,'','',{
						onClose: function(scope) {
							var obj=scope.returnValue;
							if(obj) {
								orgName.previousSibling().setValue(obj.id);
								orgName.setValue(obj.name);
							}
						}
					});
				}
			},{
	           	fieldLabel: '移动电话',
	           	xtype: 'textfield',
				name: 'mobile',
				maxLength: 32
			}]
		},{
			// 第2列
			columnWidth : .33,
			border: false,
			layout: 'form',
			defaults: {
				anchor: '100%',
				msgTarget: 'qtip',
				validateOnBlur: false
			},
			items: [{  
				allowBlank: false,
				fieldLabel: '姓名',
				xtype: 'textfield',
				name: 'userName',
				maxLength: 16
			},{
	           	fieldLabel: '是否管理员',
				name: 'isAdmin',  
				hiddenName: 'isAdmin',
				xtype: 'combo',
				mode: 'local',
				store: new Ext.data.ArrayStore({
			        fields: ['value', 'text'],
			        data: [[1, '是'], [0, '否']]
			    }),
				triggerAction: 'all',
				valueField: 'value',
				displayField: 'text',
				editable: false,
				resizeable: true,
				value: 0,
				readOnly: <%=!UserUtils.isAdmin(request)%>
			},{
	           	fieldLabel: '座机',
	           	xtype: 'textfield',
				name: 'tel',  
				maxLength: 32
			}]
		},{
			// 第3列
			columnWidth : .34,
			border: false,
			layout: 'form',
			defaults: {
				anchor: '100%',
				msgTarget: 'qtip',
				validateOnBlur: false
			},
			items: [{
	           	fieldLabel: '性别',
				name: 'gender',
				hiddenName: 'gender',
				xtype: 'combo',
				store: new EasyExt.data.ComboJsonStore({
					autoDestroy: true,
					autoLoad: true,
					sortType: 'GENDER',
					fields: ['value','text']
				}),
				emptyText: '请选择',
				valueNotFoundText: '请选择',
				mode: 'remote',
				triggerAction: 'all',
				valueField: 'value',
				displayField: 'text',
				editable: false,
				resizeable: true
			},{
				fieldLabel: '联系地址',
				xtype: 'textfield',
				name: 'address',
				maxLength: 256,
				anchor: '100%'
			},{
	           	fieldLabel: '电子邮件',
	           	xtype: 'textfield',
				name: 'email',
				maxLength: 64,
				vtype: 'email'
			}]
		}]
	},{
		fieldLabel: '备注',
		xtype: 'textarea',
		name: 'memo',
		anchor: '100%'
	}],
	listeners: {
		afterRender: function(thiz) {
			var id='${id}';
			if(!Ext.isEmpty(id)&&id!='null') {
				var url='${ctx}/user!getJSON.action';
				var params={id: id};
				Common.loadForm(thiz,url,params);
			}
		}
	},
	bbar: [{
		iconCls: 'acceptBtn',
		text: '保存',
		handler: function() {
			if (!formPanel.getForm().isValid(false)) return;
			var action;
			var id='${id}';
			var isUpdate=!Ext.isEmpty(id)&&id!='null';
			if(isUpdate) {
				action='updateJSON';
			}else {
				action='insertJSON';
			}
			formPanel.getForm().submit({
				method: 'post',
				waitTitle: ' ',
				waitMsg: '正在提交数据, 请稍后... ...',
				url: '${ctx}/user!'+action+'.action',
				params: {},
				failure: function(form,action) {
					Ext.Msg.hide();
		        	Common.parseFailureResponse(action.response);
				},
				success: function(form,action) {
					var result=action.result;
					Common.parse(result,function(buttonId) {
						Ext.Msg.hide();
						if(result.pass||buttonId=='yes') {
							++saveCounter;
							closeCurrentWindow();
						}
					});
				}
			});
		}
	},'-',{
		iconCls: 'delete2Btn',
		text: '取消',
		handler: function() {
			closeCurrentWindow();
		}
	}]
});


Ext.onReady(function() {
	var viewport = new Ext.Viewport({
		layout: 'fit',
		items: [formPanel]
	});
});
</script>
</head>

<body>
</body>
</html>